#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 20 22:21:08 2021

@author: liqingsimac
"""

'''
#############################################
##Example 4.1.1.
import numpy as np
import matplotlib.pyplot as plt

A=np.linspace(-5,5,11)
x=np.linspace(-5,5,101)

fig = plt.figure()
ax = fig.add_subplot(111)
for k in range(len(A)):
    y=A[k]*x - A[k]**2/4
    ax.plot(x,y,'b-')

yq=x**2
ax.plot(x,yq,'r-')
plt.savefig('ode-example-4-1-1.png')
#############################################
'''

'''
#############################################
##Example 4.1.2.
import numpy as np
import matplotlib.pyplot as plt

C=np.array([-3,-2,-1,1,2,3])
x=np.linspace(-5,5,101)

fig = plt.figure()
ax = fig.add_subplot(111)
for k in range(len(C)):
    y=C[k]*x**2/2 + 9/2/C[k]
    ax.plot(x,y,'b-')

yq1=3*x
ax.plot(x,yq1,'r-')
yq2=-3*x
ax.plot(x,yq2,'r-')
plt.savefig('ode-example-4-1-2.png')
#############################################
'''

'''
#############################################
##Example 4.1.3.
import numpy as np
import matplotlib.pyplot as plt

C=np.array([1,2,3,4])
x=np.linspace(-10,10,101)

fig = plt.figure()
ax = fig.add_subplot(111)
for k in range(len(C)):
    y=np.cos(C[k]-x)
    ax.plot(x,y,'b-')

yq1=np.ones_like(x)
ax.plot(x,yq1,'r-')
yq2=-1*np.ones_like(x)
ax.plot(x,yq2,'r-')
ax.set_ylim(ymin=-2,ymax=2)
plt.savefig('ode-example-4-1-3.png')
#############################################
'''


'''
#############################################
##Example 4.1.4.

import numpy as np
import matplotlib.pyplot as plt

C=np.array([-5,-3,-1,1,3,5])
v=np.linspace(-4,3,100)
x=np.zeros([len(C),len(v)])
y=np.zeros_like(x)
for k in range(len(C)):
    for m in range(len(v)):
        x[k,m]=C[k]-2*v[m]-np.log((v[m]-1)**2)
        y[k,m]=C[k]-2*v[m]-np.log((v[m]-1)**2)-v[m]**2

fig = plt.figure()
ax = fig.add_subplot(111)
for k in range(len(C)):
    ax.plot(x[k,:],y[k,:],'b-')
plt.savefig('ode-example-4-1-4.png')
#############################################
'''

'''
#############################################
##Example 4.1.4.
from sympy import symbols, log
from sympy.plotting import plot_parametric
v = symbols('v')
C=0
x = C - 2*v - log((v-1)**2)
y = C - 2*v - log((v-1)**2) - v**2
p=plot_parametric((x,y),(v,-5,4))
p.save('ode-example-4-1-4-a.png')
#############################################
'''


'''
#############################################
## Example 4.3.0.b
import sympy as sy
import sympy.plotting as syp
x, y = sy.symbols('x y')
C=[-5,-4,-3,-2,-1,0,1,2,3,4,5]
p = None
for k in range(len(C)):
  G = y-(x-C[k])**2-1
  p2 = syp.plot_implicit(G, (x,-10,10), (y,-5,30), show=False, line_color='b')
  if p:
    p.extend(p2)
  else:
    p = p2
p.show()
p.save('ode-example-4-3-0-b.png')
#############################################
'''


'''
#############################################
## Example 4.3.0.a
import sympy as sy
import sympy.plotting as syp
x, y = sy.symbols('x y')
C=[0,1,2,3,4,5,6,7,8]
p = None
for k in range(len(C)):
  G = x**2+y**2-C[k]
  p2 = syp.plot_implicit(G, (x,-4,4), (y,-4,4), show=False, line_color='b')
  if p:
    p.extend(p2)
  else:
    p = p2
p.show()
p.save('ode-example-4-3-0-a.png')
#############################################
'''


'''
#############################################
## Example 4.3.1.
import sympy as sy
import sympy.plotting as syp
x, y = sy.symbols('x y')
C=[-3,-2,-1,0,1,2,3]
#C=[0]

G1= x**2-y*(y-3)**2
p1 = syp.plot_implicit(G1, (x,-5,5), (y,-1,6), show=False, line_color='b')
p1.title(r'$x^2-y(y-3)^2=0$')
p1.show()
#p1.save('ode-example-4-3-1-a.png')

p = None
for k in range(len(C)):
  G = (x-C[k])**2-y*(y-3)**2   
  p2 = syp.plot_implicit(G, (x,-5,5), (y,-1,6), show=False, line_color='b')
  if p:
    p.extend(p2)
  else:
    p = p2
p.show()

## probably this version is too old
#syp.PlotGrid(1,2,p1,p)

#p.save('ode-example-4-3-1-b.png')
#############################################
'''

#'''
#############################################
## Midterm 2-5
import sympy as sy
import sympy.plotting as syp
x, y = sy.symbols('x y')
C=[-2,-1,-0.5-0.2,0,0.2,0.5,1,2]
p = None
for k in range(len(C)):
  G = x*y-C[k]*y+C[k]**2
  p2 = syp.plot_implicit(G, (x,-10,10), (y,-10,10), show=False,\
                         line_color='b',xlabel=None,ylabel=None)
  if p:
    p.extend(p2)
  else:
    p = p2
p3 = syp.plot_implicit(y-4*x, (x,-10,10), (y,-10,10), show=False,\
                       line_color='r')
p.extend(p3)
p.show()
#p.save('ode-midterm-2-5.png')
#############################################
#'''
